package com.cj.controller;

import com.cj.Service.DeptService;
import com.cj.Service.UserService;
import com.cj.pojo.DeptPojo;
import com.cj.pojo.UserPojo;
import com.cj.vo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class IndexController {

    //@RequestMapping("/{moduleName}")
    public String module(@PathVariable String moduleName) {
        return "pages/"+moduleName;
    }

    @GetMapping("/starter")
    public String starter(){
        return  "pages/starter";
    }

    @GetMapping("/index")
    public String index(){
        return  "pages/index";
    }

    @Autowired
    DeptService deptService;
    @Autowired
    UserService userService;
    // 获取部门名字列表
    @RequestMapping("/deptList")
    @ResponseBody
    public JsonResult deptList(Integer deptstatus){
        DeptPojo dp = new DeptPojo();
        dp.setDeptstatus(deptstatus);
        List<?> deptList = deptService.queryDpetByPojo(dp);
        // 获取当前登录用户
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        UserDetails userDetails = (UserDetails) authentication.getPrincipal();
        String username = userDetails.getUsername();
        UserPojo userPojo = new UserPojo();
        userPojo.setUsername(username);
        List<UserPojo> userList = new ArrayList<>();
        userList.add(userService.queryUserByPojo(userPojo));
        List<List<?>> list = new ArrayList<>();
        list.add(deptList);
        list.add(userList);
        return  new JsonResult(1,"成功" ,list);
    }

    //

}
